﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.DomainLayer;

//using 

namespace HA.Data
{
    [Serializable]
    public class BCWell : BCType, ICloneable
    {
        public BCWell()
            : base()
        {
            this._isPtType = true;
            this._isLnType = false;

            this._isPyType = false;

            //this._multiFlowRate = new List<double>();
            //for (int i = 0; i < this.NPeriods; i++)
            //{
            //    this._multiFlowRate.Add(0);
            //}
        }



        //double _flowRate;

        /// <summary>
        /// 流量信息
        /// </summary>
        public double FlowRate
        {
            get { return this._multiFlowRate.IsDataConst ? _multiFlowRate.ConstData : this._multiFlowRate.BCDatas[0].Value; }
            set
            {
                if (this._multiFlowRate.IsDataConst)
                    this._multiFlowRate.ConstData = value;
                else
                    this._multiFlowRate.BCDatas[0].Value = value;
            }
        }


        BCDateDataCollection _multiFlowRate = new BCDateDataCollection();

        public BCDateDataCollection MultiFlowRate
        {
            get { return _multiFlowRate; }
            set { _multiFlowRate = value; }
        }



        //public override void OnNPeriodsChanged()
        //{
        //    base.OnNPeriodsChanged();

        //    //取得之前数据的个数
        //    int n = this.MultiFlowRate.Count;



        //    //开始更新数据


        //    if (n < this.NPeriods)
        //    {
        //        int nSub =this.NPeriods-n;

        //        for (int i = 0; i < nSub; i++)
        //        {
        //            this.MultiFlowRate.Add(0);
        //        }
        //    }

        //    else
        //    {
        //        int nSub =n- this.NPeriods ;
        //        this.MultiFlowRate.RemoveRange(this.NPeriods, nSub);
        //    }


        //    //this.NPeriods;

        //}




        public object Clone()
        {

            BCWell bcw =(BCWell)this.MemberwiseClone();

            bcw._multiFlowRate = (BCDateDataCollection)this._multiFlowRate.Clone();


            return bcw;

        }

        public override void MapToModflow(List<double> stressPeriods, List<ValueResult> ijkList, ModFlowData mf, FeatureObject owner)
        {
            List<int> indice = new List<int>();

            List<Well> wells = new List<Well>();



            foreach (ValueResult item in ijkList)
            {
                indice.Add(mf.GridData.GetIndex(item.I, item.J, item.K));

                Well well = new Well(item.I, item.J, item.K, mf.GridData.RowsCount, mf.GridData.ColsCount, mf.GridData.LayersCount, mf.StressPeriods.InnerList.Count);

                this.assistMapToModFlow(stressPeriods, well.RechargeRates, _multiFlowRate);

                //for (int i = 0; i < this.NPeriods; i++)
                //{
                //    well.RechargeRates[i] = this._multiFlowRate[i];
                //}
                wells.Add(well);
            }


            //mf.SourceSinks.Wells.UpdateWells(wells, indice);
            mf.SourceSinks.Wells.AddTempWells(wells);

        }
    }
}
